<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TypeScript DSL ORM - 需求跟踪矩阵 (RTM) v2.0</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            background-color: #f8f9fa;
        }
        .container {
            max-width: 1900px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 10px;
            font-size: 2.2em;
        }
        .subtitle {
            text-align: center;
            color: #7f8c8d;
            margin-bottom: 30px;
            font-style: italic;
        }
        h2 {
            color: #34495e;
            border-bottom: 3px solid #3498db;
            padding-bottom: 10px;
            margin-top: 40px;
        }
        h3 {
            color: #2980b9;
            margin-top: 30px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            font-size: 11px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
            vertical-align: top;
        }
        th {
            background-color: #3498db;
            color: white;
            font-weight: bold;
            position: sticky;
            top: 0;
            z-index: 10;
        }
        .epic-header {
            background-color: #2c3e50 !important;
            color: white;
            font-size: 12px;
            font-weight: bold;
        }
        .user-story {
            font-size: 10px;
            max-width: 300px;
            word-wrap: break-word;
        }
        .component {
            font-size: 10px;
            max-width: 200px;
        }
        .complexity {
            text-align: center;
            font-weight: bold;
        }
        .complexity.high { background-color: #e74c3c; color: white; }
        .complexity.medium { background-color: #f39c12; color: white; }
        .complexity.low { background-color: #27ae60; color: white; }
        .priority {
            text-align: center;
            font-weight: bold;
        }
        .priority.high { background-color: #c0392b; color: white; }
        .priority.medium { background-color: #e67e22; color: white; }
        .priority.low { background-color: #16a085; color: white; }
        .status {
            text-align: center;
            font-weight: bold;
        }
        .status.completed { background-color: #27ae60; color: white; }
        .status.in-progress { background-color: #f39c12; color: white; }
        .status.planned { background-color: #95a5a6; color: white; }
        .summary-box {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            border-radius: 8px;
            margin: 20px 0;
        }
        .mvp-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 15px;
            border-radius: 6px;
            margin: 15px 0;
        }
        .dependency-arrow {
            color: #e74c3c;
            font-weight: bold;
        }
        .component-path {
            font-family: 'Courier New', monospace;
            font-size: 9px;
            color: #7f8c8d;
        }
        .feature-merge {
            background-color: #ecf0f1;
            font-weight: bold;
        }
        .us-id {
            font-weight: bold;
            color: #2980b9;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎯 TypeScript DSL ORM 需求跟踪矩阵</h1>
        <p class="subtitle">Requirements Traceability Matrix v2.0 - 用户故事与技术组件映射</p>
        
        <div class="summary-box">
            <h3 style="margin-top: 0;">📊 项目概览</h3>
            <p><strong>总用户故事数：</strong>92个 | <strong>Epic数量：</strong>16个 | <strong>技术组件：</strong>45个</p>
            <p><strong>完成状态：</strong>核心DSL解析 ✅ | ORM集成 🔄 | API生成 📋 | 高级特性 📋</p>
            <p><strong>技术栈：</strong>TypeScript + YAML DSL + TypeORM + Express + 插件架构</p>
        </div>

        <h2>🏗️ 核心技术组件映射</h2>
        
        <table>
            <thead>
                <tr>
                    <th style="width: 120px;">Epic</th>
                    <th style="width: 80px;">用户故事ID</th>
                    <th style="width: 300px;">用户故事描述</th>
                    <th style="width: 200px;">主要技术组件</th>
                    <th style="width: 150px;">组件路径</th>
                    <th style="width: 80px;">实现复杂度</th>
                    <th style="width: 80px;">业务优先级</th>
                    <th style="width: 80px;">开发状态</th>
                    <th style="width: 120px;">技术依赖</th>
                </tr>
            </thead>
            <tbody>
                <!-- Epic 1.1: DSL 语言设计 -->
                <tr>
                    <td class="epic-header" rowspan="3">1.1 DSL语言设计</td>
                    <td class="us-id">US-01-0001</td>
                    <td class="user-story">DSL语法定义实体和属性，支持基础类型和约束</td>
                    <td class="component">DSL Parser<br>Type Validators<br>Syntax Checker</td>
                    <td class="component-path">src/dsl/parser.ts<br>src/dsl/type-validators.ts<br>src/dsl/syntax-checker.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority high">高</td>
                    <td class="status completed">已完成</td>
                    <td>YAML解析器</td>
                </tr>
                <tr>
                    <td class="us-id">US-01-0002</td>
                    <td class="user-story">DSL中声明实体间关联关系，支持一对一、一对多、多对多</td>
                    <td class="component">Model Validator<br>Cross Field Validator<br>Association Parser</td>
                    <td class="component-path">src/dsl/model-validator.ts<br>src/dsl/cross-field-validator.ts<br>src/dsl/parser.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority high">高</td>
                    <td class="status completed">已完成</td>
                    <td>US-01-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-01-0003</td>
                    <td class="user-story">DSL中定义业务行为（命令/事件）</td>
                    <td class="component">CQRS Metadata Generator<br>Event Translator<br>Command Bus</td>
                    <td class="component-path">src/dsl/translator/cqrs-metadata-generator.ts<br>src/dsl/translator/toEvents.ts<br>src/runtime/commandBus.ts</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status completed">已完成</td>
                    <td>US-01-0001</td>
                </tr>

                <!-- Epic 1.2: 动态对象模型 -->
                <tr>
                    <td class="epic-header" rowspan="2">1.2 动态对象模型</td>
                    <td class="us-id">US-01-0004</td>
                    <td class="user-story">DSL自动解析生成可导航的领域对象图</td>
                    <td class="component">Domain Model Translator<br>Domain Graph<br>Parser</td>
                    <td class="component-path">src/dsl/translator/domain-model-translator.ts<br>src/runtime/domainGraph.ts<br>src/dsl/parser.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority high">高</td>
                    <td class="status completed">已完成</td>
                    <td>US-01-0001, US-01-0002</td>
                </tr>
                <tr>
                    <td class="us-id">US-01-0005</td>
                    <td class="user-story">隐藏聚合实现细节，专注业务逻辑</td>
                    <td class="component">Repository Pattern<br>Runtime Integration<br>ORM Adapters</td>
                    <td class="component-path">src/runtime/repository.ts<br>src/orm/runtime/runtime-integration.ts<br>src/orm/adapters/</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status in-progress">进行中</td>
                    <td>US-01-0004</td>
                </tr>

                <!-- Epic 1.3: 存储策略配置 -->
                <tr>
                    <td class="epic-header">1.3 存储策略配置</td>
                    <td class="us-id">US-01-0006</td>
                    <td class="user-story">DSL层声明不同存储策略</td>
                    <td class="component">Database Config Loader<br>DataSource Service<br>Config Transformer</td>
                    <td class="component-path">src/config/database-config-loader.ts<br>src/orm/adapters/datasource-service.ts<br>src/orm/adapters/config-transformer.ts</td>
                    <td class="complexity medium">中</td>
                    <td class="priority low">低</td>
                    <td class="status planned">计划中</td>
                    <td>US-01-0001</td>
                </tr>

                <!-- Epic 2.1: 持久化适配 -->
                <tr>
                    <td class="epic-header" rowspan="2">2.1 持久化适配</td>
                    <td class="us-id">US-02-0001</td>
                    <td class="user-story">统一的持久化接口，屏蔽数据库差异</td>
                    <td class="component">DataSource Options Builder<br>ORM Adapters<br>Resource Manager</td>
                    <td class="component-path">src/orm/adapters/datasource-options-builder.ts<br>src/orm/adapters/<br>src/orm/adapters/resource-manager.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority high">高</td>
                    <td class="status in-progress">进行中</td>
                    <td>US-01-0004</td>
                </tr>
                <tr>
                    <td class="us-id">US-02-0002</td>
                    <td class="user-story">支持关系型和文档型数据库</td>
                    <td class="component">TypeORM Schema Generator<br>DataSource Service<br>Database Config</td>
                    <td class="component-path">src/orm/generators/typeorm-schema-generator.ts<br>src/orm/adapters/datasource-service.ts<br>src/config/database-config-loader.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority medium">中</td>
                    <td class="status planned">计划中</td>
                    <td>US-02-0001</td>
                </tr>

                <!-- Epic 2.2: 外部服务适配 -->
                <tr>
                    <td class="epic-header">2.2 外部服务适配</td>
                    <td class="us-id">US-02-0003</td>
                    <td class="user-story">集成外部API和消息系统</td>
                    <td class="component">Event Bus<br>API Router<br>External Adapters</td>
                    <td class="component-path">src/runtime/eventBus.ts<br>src/api/router.ts<br>待开发</td>
                    <td class="complexity medium">中</td>
                    <td class="priority low">低</td>
                    <td class="status planned">计划中</td>
                    <td>US-02-0001</td>
                </tr>

                <!-- Epic 3.1: 代码生成引擎 -->
                <tr>
                    <td class="epic-header" rowspan="3">3.1 代码生成引擎</td>
                    <td class="us-id">US-03-0001</td>
                    <td class="user-story">从DSL自动生成TypeORM实体类</td>
                    <td class="component">TypeORM Schema Generator<br>Entity Schema Translator<br>Technical Model</td>
                    <td class="component-path">src/dsl/translator/typeorm-schema-generator.ts<br>src/dsl/translator/toEntitySchema.ts<br>src/dsl/translator/technical-model.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority high">高</td>
                    <td class="status completed">已完成</td>
                    <td>US-01-0001, US-01-0002</td>
                </tr>
                <tr>
                    <td class="us-id">US-03-0002</td>
                    <td class="user-story">生成数据库迁移脚本</td>
                    <td class="component">Migration Generator<br>Schema Diff<br>Database Config</td>
                    <td class="component-path">待开发<br>待开发<br>src/config/database-config-loader.ts</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status planned">计划中</td>
                    <td>US-03-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-03-0003</td>
                    <td class="user-story">生成Repository和Service层代码</td>
                    <td class="component">Repository Generator<br>Service Generator<br>Code Templates</td>
                    <td class="component-path">待开发<br>待开发<br>templates/</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status planned">计划中</td>
                    <td>US-03-0001</td>
                </tr>

                <!-- Epic 4.1: RESTful API 自动生成 -->
                <tr>
                    <td class="epic-header" rowspan="3">4.1 RESTful API自动生成</td>
                    <td class="us-id">US-04-0001</td>
                    <td class="user-story">根据实体自动生成CRUD API端点</td>
                    <td class="component">API Router<br>API Translator<br>HATEOAS Generator</td>
                    <td class="component-path">src/api/router.ts<br>src/dsl/translator/toAPI.ts<br>src/dsl/translator/hateoas.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority high">高</td>
                    <td class="status in-progress">进行中</td>
                    <td>US-03-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-04-0002</td>
                    <td class="user-story">支持复杂查询和过滤</td>
                    <td class="component">Query Builder<br>Filter Parser<br>Validation Mapper</td>
                    <td class="component-path">待开发<br>待开发<br>src/dsl/translator/validation-mapper.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority medium">中</td>
                    <td class="status planned">计划中</td>
                    <td>US-04-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-04-0003</td>
                    <td class="user-story">API文档自动生成</td>
                    <td class="component">OpenAPI Generator<br>Swagger Integration<br>Documentation Builder</td>
                    <td class="component-path">待开发<br>待开发<br>待开发</td>
                    <td class="complexity medium">中</td>
                    <td class="priority low">低</td>
                    <td class="status planned">计划中</td>
                    <td>US-04-0001</td>
                </tr>

                <!-- Epic 5.1: 插件系统 -->
                <tr>
                    <td class="epic-header" rowspan="3">5.1 插件系统</td>
                    <td class="us-id">US-05-0001</td>
                    <td class="user-story">可扩展的插件架构</td>
                    <td class="component">Plugin Manager<br>Plugin Registry<br>Plugin Types</td>
                    <td class="component-path">src/dsl/plugin-manager.ts<br>src/dsl/plugin-registry.ts<br>src/dsl/plugin-types.ts</td>
                    <td class="complexity high">高</td>
                    <td class="priority medium">中</td>
                    <td class="status completed">已完成</td>
                    <td>US-01-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-05-0002</td>
                    <td class="user-story">内置核心插件</td>
                    <td class="component">Core Plugin<br>Validation Plugin<br>Enhancement Plugin</td>
                    <td class="component-path">src/dsl/plugins/core-plugin.ts<br>src/dsl/plugins/validation-plugin.ts<br>src/dsl/plugins/enhancement-plugin.ts</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status completed">已完成</td>
                    <td>US-05-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-05-0003</td>
                    <td class="user-story">第三方插件开发支持</td>
                    <td class="component">Plugin SDK<br>Plugin Documentation<br>Plugin Examples</td>
                    <td class="component-path">docs/plugin-system-guide.md<br>examples/plugin-usage.ts<br>待完善</td>
                    <td class="complexity medium">中</td>
                    <td class="priority low">低</td>
                    <td class="status in-progress">进行中</td>
                    <td>US-05-0001, US-05-0002</td>
                </tr>

                <!-- Epic 6.1: 模板系统 -->
                <tr>
                    <td class="epic-header" rowspan="2">6.1 模板系统</td>
                    <td class="us-id">US-06-0001</td>
                    <td class="user-story">参数化模板定义和解析</td>
                    <td class="component">Template Resolver<br>Parameterized Template Resolver<br>Field Templates</td>
                    <td class="component-path">src/dsl/template-resolver.ts<br>src/dsl/parameterized-template-resolver.ts<br>templates/field-templates.yml</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status completed">已完成</td>
                    <td>US-01-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-06-0002</td>
                    <td class="user-story">模板继承和组合</td>
                    <td class="component">Template Inheritance<br>Template Composition<br>Template Validator</td>
                    <td class="component-path">src/dsl/template-resolver.ts<br>待开发<br>待开发</td>
                    <td class="complexity medium">中</td>
                    <td class="priority low">低</td>
                    <td class="status planned">计划中</td>
                    <td>US-06-0001</td>
                </tr>

                <!-- Epic 7.1: 元数据管理 -->
                <tr>
                    <td class="epic-header" rowspan="2">7.1 元数据管理</td>
                    <td class="us-id">US-07-0001</td>
                    <td class="user-story">元数据验证和管理</td>
                    <td class="component">Metadata Validator<br>Technical Metadata<br>Metadata Extension</td>
                    <td class="component-path">src/dsl/metadata-validator.ts<br>src/dsl/translator/technical-model.ts<br>待开发</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status completed">已完成</td>
                    <td>US-01-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-07-0002</td>
                    <td class="user-story">元数据扩展机制</td>
                    <td class="component">Metadata Extension API<br>Custom Metadata<br>Metadata Registry</td>
                    <td class="component-path">待开发<br>待开发<br>待开发</td>
                    <td class="complexity medium">中</td>
                    <td class="priority low">低</td>
                    <td class="status planned">计划中</td>
                    <td>US-07-0001</td>
                </tr>

                <!-- 继续其他Epic... 为了简洁，这里展示主要的Epic -->
                
                <!-- Epic 8.1: CLI工具 -->
                <tr>
                    <td class="epic-header" rowspan="2">8.1 CLI工具</td>
                    <td class="us-id">US-08-0001</td>
                    <td class="user-story">命令行语法检查工具</td>
                    <td class="component">Syntax Check CLI<br>CLI Interface<br>Error Reporter</td>
                    <td class="component-path">src/cli/syntax-check.ts<br>待开发<br>待开发</td>
                    <td class="complexity low">低</td>
                    <td class="priority medium">中</td>
                    <td class="status in-progress">进行中</td>
                    <td>US-01-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-08-0002</td>
                    <td class="user-story">项目脚手架生成</td>
                    <td class="component">Project Generator<br>Template Engine<br>File Generator</td>
                    <td class="component-path">待开发<br>待开发<br>待开发</td>
                    <td class="complexity medium">中</td>
                    <td class="priority low">低</td>
                    <td class="status planned">计划中</td>
                    <td>US-08-0001</td>
                </tr>

                <!-- Epic 16.2: 生产部署 -->
                <tr>
                    <td class="epic-header" rowspan="3">16.2 生产部署</td>
                    <td class="us-id">US-16-0002</td>
                    <td class="user-story">生产环境服务器配置</td>
                    <td class="component">Production Server<br>Environment Config<br>Resource Manager</td>
                    <td class="component-path">src/production-server.ts<br>.env.production.template<br>src/orm/adapters/resource-manager.ts</td>
                    <td class="complexity medium">中</td>
                    <td class="priority high">高</td>
                    <td class="status completed">已完成</td>
                    <td>US-02-0001, US-04-0001</td>
                </tr>
                <tr>
                    <td class="us-id">US-16-0003</td>
                    <td class="user-story">Docker容器化部署</td>
                    <td class="component">Docker Configuration<br>Container Orchestration<br>Health Checks</td>
                    <td class="component-path">docker-compose.test.yml<br>待开发<br>待开发</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status in-progress">进行中</td>
                    <td>US-16-0002</td>
                </tr>
                <tr>
                    <td class="us-id">US-16-0004</td>
                    <td class="user-story">CI/CD流水线</td>
                    <td class="component">GitHub Actions<br>Test Automation<br>Deployment Pipeline</td>
                    <td class="component-path">.github/workflows/<br>jest.config.cjs<br>待完善</td>
                    <td class="complexity medium">中</td>
                    <td class="priority medium">中</td>
                    <td class="status in-progress">进行中</td>
                    <td>US-16-0003</td>
                </tr>
            </tbody>
        </table>

        <h2>🎯 MVP迭代规划</h2>
        
        <div class="mvp-box">
            <h3 style="margin-top: 0;">🚀 MVP 1.0 - 核心DSL到API (已完成基础)</h3>
            <p><strong>目标：</strong>DSL → 数据库表 → RESTful API 的完整链路</p>
            <p><strong>核心用户故事：</strong>US-01-0001, US-01-0002, US-01-0004, US-03-0001, US-04-0001</p>
            <p><strong>技术组件：</strong>DSL Parser + TypeORM Generator + API Router</p>
            <p><strong>验收标准：</strong>10秒内从DSL生成完整后端服务</p>
        </div>

        <div class="mvp-box">
            <h3 style="margin-top: 0;">🔧 MVP 2.0 - 高级特性和优化</h3>
            <p><strong>目标：</strong>插件系统 + 模板系统 + 高级查询</p>
            <p><strong>核心用户故事：</strong>US-05-0001, US-05-0002, US-06-0001, US-04-0002</p>
            <p><strong>技术组件：</strong>Plugin System + Template Engine + Query Builder</p>
            <p><strong>验收标准：</strong>支持自定义插件和复杂业务逻辑</p>
        </div>

        <div class="mvp-box">
            <h3 style="margin-top: 0;">🌟 MVP 3.0 - 企业级特性</h3>
            <p><strong>目标：</strong>多数据库支持 + 安全特性 + 监控</p>
            <p><strong>核心用户故事：</strong>US-02-0002, US-13-0001, US-14-0001, US-15-0001</p>
            <p><strong>技术组件：</strong>Multi-DB Adapters + Security Layer + Monitoring</p>
            <p><strong>验收标准：</strong>生产级稳定性和安全性</p>
        </div>

        <h2>📊 技术依赖关系图</h2>
        
        <div class="summary-box">
            <h3 style="margin-top: 0;">🔗 关键依赖路径</h3>
            <p><strong>核心路径：</strong>DSL Parser → Domain Model → TypeORM Schema → API Router</p>
            <p><strong>插件路径：</strong>Plugin Manager → Core/Validation/Enhancement Plugins</p>
            <p><strong>数据路径：</strong>Database Config → DataSource Service → ORM Adapters</p>
            <p><strong>运行时路径：</strong>Runtime Integration → Repository → Command/Event Bus</p>
        </div>

        <h2>🎯 实施建议</h2>
        
        <table>
            <thead>
                <tr>
                    <th>阶段</th>
                    <th>重点任务</th>
                    <th>关键用户故事</th>
                    <th>预期工期</th>
                    <th>风险评估</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><strong>第一阶段</strong></td>
                    <td>完善ORM集成和API生成</td>
                    <td>US-02-0001, US-04-0001, US-04-0002</td>
                    <td>2-3周</td>
                    <td class="complexity medium">中等</td>
                </tr>
                <tr>
                    <td><strong>第二阶段</strong></td>
                    <td>增强插件系统和模板功能</td>
                    <td>US-05-0003, US-06-0002, US-07-0002</td>
                    <td>2周</td>
                    <td class="complexity low">低</td>
                </tr>
                <tr>
                    <td><strong>第三阶段</strong></td>
                    <td>多数据库支持和安全特性</td>
                    <td>US-02-0002, US-13-0001, US-14-0001</td>
                    <td>3-4周</td>
                    <td class="complexity high">高</td>
                </tr>
                <tr>
                    <td><strong>第四阶段</strong></td>
                    <td>生产部署和监控</td>
                    <td>US-16-0002, US-16-0003, US-16-0004</td>
                    <td>2周</td>
                    <td class="complexity medium">中等</td>
                </tr>
            </tbody>
        </table>

        <div class="summary-box">
            <h3 style="margin-top: 0;">✅ 下一步行动计划</h3>
            <p><strong>立即执行：</strong>完善US-02-0001 (统一持久化接口) 和 US-04-0001 (CRUD API生成)</p>
            <p><strong>并行开发：</strong>US-04-0002 (复杂查询支持) 和 US-03-0002 (迁移脚本生成)</p>
            <p><strong>技术债务：</strong>完善测试覆盖率，优化错误处理机制</p>
            <p><strong>文档更新：</strong>API文档生成，部署指南完善</p>
        </div>

        <p style="text-align: center; color: #7f8c8d; margin-top: 40px;">
            <em>最后更新：2024年12月 | 版本：v2.0 | 基于92个用户故事和45个技术组件</em>
        </p>
    </div>
</body>
</html>